<?
/**
 * $Id: $
 * $GI = information of a game
 * $PI[n] n>0 = information of a player
 */

// sort players by score
$keys = array_keys($PIS);
$scores = array();
$noscores = array();
for ($i = 1; $i < count($keys); $i++) {
	$PI = $PIS[$i];
	if (isset($PI['PlayerScore']))
		$scores[$i] = $PI['PlayerScore'];
	else 
		$noscores[$i] = true;
}
arsort($scores);

?>
<h2><?=tr('Game informations')?></h2>
<div class="game">
<?
	$l = new htmlList();
	$l->add('Status', $GI['GameStatus']);
	$l->add('Match created on', fgsUtils::formatDate($GI['GameTimeCreated']));
	$l->add('Last update on', fgsUtils::formatDate($GI['GameLastUpdate']));
	$l->add('Time elapsed', fgsUtils::formatSeconds($GI['GameLastUpdate'] - $GI['GameTimeCreated']));
	$l->add('Version', $GI['GameVersion']);
	echo $l->render();
?>
</div>
<?

	// display player who have score
	if (count($scores)) {
		echo sprintf('<h2>%s</h2>', tr('Scores'));
		foreach ($scores as $k => $v)
			displayPlayer($PIS[$k]);
	}

	// display player who don't have score
	if (count($noscores)) {
		echo '<h2>No scored</h2>';
		foreach ($noscores as $k => $v)
			displayPlayer($PIS[$k]);
	}

	function displayPlayer($PI) {
		$l = new htmlList();
		$random = microtime();
		$playerlogin = $PI['PlayerLogin'];
?>
	<div class="player">
		<h3 onmouseover="show('i<?=$random?>')" onmouseout="hide('i<?=$random?>')">
		<div style="float: right;"><?=fgsUtils::formatField('Score', $PI['PlayerScore'], 'No score')?></div>
		<?
			echo fgsUtils::formatField(false, $PI['PlayerName'], '-');
			if (empty($playerlogin)) {
				echo '<span class="anonymous">';
				echo tr('(anonymous)');
				echo '</span>';
			} else {
		?>
		<a href="<?fgsBase::link('player', array($playerlogin))?>"><?
			echo '<span class="identified">';
			echo sprintf(tr('(identified by %s)'), $playerlogin);
			echo '</span>';
		?></a><?
			}
		?>
		</h3>
		<?
		$l->add($PI['PlayerStatus']);
		$l->add('Version', $PI['PlayerGameVersion']);
		echo $l->render('i'.$random, 'hide');
		?>
	</div>
<?
	}
?>
